﻿using System;
using System.IO;
using System.Web.Mvc;
using Ctef.Web.Interfaces;
using Ctef.Web.Repositories;
using System.Threading;

namespace Ctef.Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly IHomepageRepository rep;

        public HomeController()
            : this(new HomepageRepository())
        {
        }

        public HomeController(IHomepageRepository homepageRepository)
        {
            if (homepageRepository == null)
            {
                throw new ArgumentNullException("homepageRepository");
            }

            rep = homepageRepository;
        }

        [HttpGet]
        [OutputCache(CacheProfile = "Cache3Seconds")]
        public ActionResult Index()
        {
            var culture = Thread.CurrentThread.CurrentUICulture.Name;
            var model = rep.GetHomepageModel(culture, Path.Combine(Request.PhysicalApplicationPath, "App_Data"));
            return View(model);
        }

        protected override void HandleUnknownAction(string actionName)
        {
            this.View("Index").ExecuteResult(this.ControllerContext);
        }
    }
}
